<template>

  <!-- header -->
  <div class="nav-container page-component">
    <!--左侧导航 #start -->
    <div class="nav left-nav">
      <div class="nav-item ">
        <span class="v-link  clickable dark" onclick="javascript:window.location='/user'">实名认证 </span>
      </div>
      <div class="nav-item">
        <span class="v-link clickable dark" onclick="javascript:window.location='/order'"> 挂号订单 </span>
      </div>
      <div class="nav-item ">
        <span class="v-link clickable dark" onclick="javascript:window.location='/patient'"> 就诊人管理 </span>
      </div>
      <div class="nav-item selected">
        <span class="v-link selected dark" onclick="javascript:window.location='/user/edit'"> 修改账号信息 </span>
      </div>
      <div class="nav-item ">
        <span class="v-link clickable dark"> 意见反馈 </span>
      </div>
    </div>
    <!-- 左侧导航 #end -->

    <!-- 右侧内容 #start -->
    <div class="page-container">
      <div>
        <div class="title"> 修改账户信息</div>
        <el-card class="box-card">
          <div class="status-bar" v-if="userInfo.authStatus == 0">
            <div class="status-wrapper"><span class="iconfont"></span>{{ userInfo.param.authStatusString }}</div>
          </div>
          <div class="tips" v-if="userInfo.authStatus == 0"><span class="iconfont"></span>
            完成实名认证后才能添加就诊人，正常进行挂号，为了不影响后续步骤，建议提前实名认证。
          </div>
          <div class="form-wrapper" v-if="userInfo.authStatus == 0">

            <div>

              <el-form label-width="110px" label-position="right">
                <el-form-item prop="name" label="姓名：" class="form-normal">
                  <el-input v-model="userInfo.name" style="width: 370px"></el-input>
                </el-form-item>
                <el-form-item prop="name" label="昵称：">
                  <el-input v-model="userInfo.nickName" style="width: 370px"></el-input>
                </el-form-item>
                <el-form-item prop="name" label="电话：">
                  <el-input v-model="userInfo.phone" style="width: 370px"></el-input>
                </el-form-item>

                <div class="button-wrapper" style="margin:10px 220px">
                  <div class="v-button" @click="editUserInfo">修改</div>
                </div>
              </el-form>
            </div>







          </div>

            <div class="context-container" v-if="userInfo.authStatus != 0">
              <div>
                <el-form label-width="110px" label-position="right">
                  <el-form-item prop="name" label="姓名：" class="form-normal">
                    <el-input v-model="userInfo.name" style="width: 370px"></el-input>
                  </el-form-item>
                  <el-form-item prop="name" label="昵称：">
                    <el-input v-model="userInfo.nickName" style="width: 370px"></el-input>
                  </el-form-item>
                  <el-form-item prop="name" label="电话：">
                    <el-input v-model="userInfo.phone" style="width: 370px"></el-input>
                  </el-form-item>
                  <el-form-item prop="name" label="证件类型：">
                    <el-input v-model="userInfo.certificatesType" readonly style="width: 370px"></el-input>
                  </el-form-item>

                  <el-form-item prop="name" label="证件号码：" >
                    <el-input v-model="userInfo.certificatesNo" readonly style="width: 370px"></el-input>
                  </el-form-item>
                  <el-form-item prop="name" label="证件照：">
                    <div class="upload-wrapper">
                      <div class="avatar-uploader">
                          <div class="upload-inner-wrapper">
                            <img v-if="userInfo.certificatesUrl" :src="userInfo.certificatesUrl" class="avatar">
                            <img v-if="!userInfo.certificatesUrl" src="//img.114yygh.com/static/web/auth_example.png" class="avatar">
                          </div>
                      </div>
                    </div>
                  </el-form-item>
                    <div class="button-wrapper" style="margin:10px 220px">
                      <div class="v-button" @click="editUserInfo">修改</div>
                    </div>
                </el-form>
              </div>
            </div>
          </el-card>
      </div>
    </div>
    <!-- 右侧内容 #end -->

    <!-- 登录弹出框 -->
  </div>
  <!-- footer -->
</template>

<script>
  import '~/assets/css/hospital_personal.css'
  import '~/assets/css/hospital.css'
  import '~/assets/css/personal.css'

  import dictApi from '@/api/cmn/dict'
  import userInfoApi from '@/api/user/userInfo'

  const defaultForm = {
    name: '',
    certificatesType: '',
    certificatesNo: '',
    certificatesUrl: ''
  }
  export default {

    data() {
      return {

        userAuah: defaultForm,
        certificatesTypeList: [],
        fileUrl:'http://localhost:9002/api/oss/file/fileUpload?fileHost=userAuah',

        userInfo: {
          param: {}
        },

        submitBnt: '提交'
      }
    },

    created() {
      this.init()
    },

    methods: {
      init() {
        this.getUserInfo()

        this.getDict()
      },

      getUserInfo() {
        userInfoApi.getUserInfo().then(response => {
          this.userInfo = response.data
          console.log(this.userInfo)
          // console.log(this.userInfo.certificatesType)
        })
      },
      editUserInfo(){
        // console.log(this.userInfo)
        if(this.submitBnt == '正在修改...') {
          this.$message.info('重复修改')
          return
        }
        this.submitBnt = '正在修改...'
        if (this.userAuah.authStatus==0){
          this.$message.success("提交实名认证")
          userInfoApi.saveUserAuah(this.userAuah).then(response => {
            this.$message.success("提交实名认证")
            window.location.reload()
          }).catch(e => {
            this.$message.success("实名认证失败")
          })
        }
        userInfoApi.editUserInfo(this.userInfo).then(response => {
          this.$message.success("修改成功")
          window.location.reload()
        }).catch(e => {
          this.submitBnt = '修改'
        })
      },

      getDict() {
        dictApi.findByDictCode("CertificatesType").then(response => {
          this.certificatesTypeList = response.data
        })
      },

      onUploadSuccess(response, file) {
        // debugger
        if(response.code !== 200) {
          this.$message.error("上传失败")
          return
        }
        // 填充上传文件列表
        this.userAuah.certificatesUrl = file.response.data

      }
    }
  }
</script>
<style>
  .header-wrapper .title {
    font-size: 16px;
    margin-top: 0;
  }

  .content-wrapper {
    margin-left: 0;
  }

  .patient-card .el-card__header .detail {
    font-size: 14px;
  }

  .page-container .title {
    letter-spacing: 1px;
    font-weight: 700;
    color: #333;
    font-size: 16px;
    margin-top: 0;
    margin-bottom: 20px;
  }

  .page-container .tips {
    width: 100%;
    padding-left: 0;
  }

  .page-container .form-wrapper {
    padding-left: 92px;
    width: 580px;
  }

  .form-normal {
    height: 40px;
  }
  .bottom-wrapper{
    width: 100%;
    padding: 0;
    margin-top: 0;
  }
</style>
